//
//  AudioStreamPlayer.h
//  AudioProj
//
//  Created by  on 13-4-11.
//  Copyright (c) 2013年 AISpeech. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AudioStreamAnalyzer.h"

typedef enum {
    ASP_IDLE = 0,
    ASP_PLAYING,
    ASP_PAUSE,
    ASP_TOSTOP,
    ASP_STOPED,
    ASP_MAX,
} PlayerStatus;

typedef enum {
    E_READY_PLAY = 0,
    E_STARTED_PLAY,
    E_FINISH_PLAY,
} EventType;

@interface AudioStreamPlayer : NSObject
{
@private
    AudioQueueRef audioQueue;
    AudioStreamAnalyzer *audioAnalyzer;
    NSURLConnection *urlConnection;
    NSString *url;
    BOOL isDownloading;//是否正在下载
    AudioTimeStamp seekTime;
    NSUInteger remainCount;
    SInt64 fileLength;
    BOOL isReBuffer;
    Float64 bufferLength;
    Float64 bufferTime;
    NSMutableData *totalAudioData;
    PlayerStatus playerStatus;
    AudioQueueTimelineRef timeLine;
    id pUserData;
    // 用于MP3计算比特率
	UInt64 processedPacketsCount;
	UInt64 processedPacketsSizeTotal;
    Float64 progress;
    Float64 duration;
    Float64 buffedProgress;
    id delegate;
    SEL audioCallback;
    EventType firedEvent;
    BOOL isNoDataPause;
    BOOL isLast;
}

@property(nonatomic,readonly)NSString *url;
@property(nonatomic,assign)Float64 bufferTime;
@property(nonatomic,readonly)Float64 progress;
@property(nonatomic,readonly)Float64 duration;
@property(nonatomic,readonly)Float64 buffedProgress;
@property(nonatomic,retain)id pUserData;
@property(nonatomic,assign)SEL audioCallback;

- (id)init;
//初始化状态
-(void)initState ;
- (BOOL)destroy;
- (void)setDelegateObject:(id)cbObj setCbName:(NSString *)selectorName;
- (BOOL)feedData:(NSData *)data;
- (BOOL)feedData:(NSData *)data isWavType:(BOOL)isWav;
- (BOOL)play;
- (BOOL)pause;
- (BOOL)stop:(BOOL)flag;
- (BOOL)reset;
- (Float64)progress;
- (Float64)duration;
- (BOOL)seekToTime:(Float64)newTime;
- (PlayerStatus)getStatus;
- (void)setStatus:(PlayerStatus)status;
- (EventType)getEvent;

@end
